import Vue from 'vue';
import router from './index';
import { ACCESS_TOKEN } from '@/store/mutation-types';
// import { nextTick } from 'vue/types/umd';

const whiteList = ['/login'];


router.beforeEach((to, from, next) => {
	if (to.path === '/login' || whiteList.indexOf(to.path) !== -1) {
		next();// 出口
	} else {
		if (Vue.ls.get(ACCESS_TOKEN)) { // 通过vuex state获取当前的token是否存在
			next();
		} else {
			next({
				path: '/login',
				query: { redirect: to.fullPath } // 将跳转的路由path作为参数，登录成功后跳转到该路由
			});
		}
	}
});

